﻿using DynamicQuartz.Common;
using DynamicQuartz.Common.Configuration;
using Quartz;

namespace DynamicQuartz.Schedule.Core
{
    [DisallowConcurrentExecution]
    public abstract class QuartzScheduleBase : IJob
    {
        /// <summary>
        /// 定时器名称(要保证定时器名称唯一)
        /// </summary>
        public abstract string Name { get; }

        /// <summary>
        /// 定时器Cron表达式
        /// https://cron.qqe2.com/
        /// </summary>
        public abstract string Cron { get; }

        /// <summary>
        /// 定时器描述
        /// </summary>
        public virtual string Description { get; }

        /// <summary>
        /// 是否开启
        /// </summary>
        public virtual bool Open { get => true; }


        public abstract Task Execute(IJobExecutionContext context);


        protected bool GetEnvironmentOpen()
        {
            var env = ConfigurationHelper.GetSection("Environment");
            if (env == "Dev")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
